@comment{'A template @DataObject that creates cheatsheets doc'}

@includeNamed{'common-lib.templ'}

@code{

  /**
   * Render a tag link to an its plain value, this function is used as parameter of the
   * renderDocToHtml function when it needs to render tag links.
   */
  def renderTagLinkToHtml(tag) {
    return tag.name;
  }

  /**
   * Return the formatted property data type.
   */
  def getDataType(type) {
    var kind = type.kind;
    if (kind.basic) {
      if (kind == CLASS_STRING) {
        return 'String';
      }
      var typeName = type.name;
      if (typeName == 'java.lang.Boolean' || typeName == 'boolean') {
        return "Boolean";
      }
      if (typeName == 'java.lang.Integer' || typeName == 'int' ||
          typeName == 'java.lang.Long' || typeName == 'long') {
        return "Number";
      }
    } else if (kind == CLASS_DATA_OBJECT) {
      return 'link:' + type.raw.simpleName + '.html[' + type.raw.simpleName + ']';
    }
    System.out.println("unhandled type " + type);
    return null;
  }
}

== @{type.simpleName}\n
\n
@if{doc != null}
++++\n
@{renderDocToHtml('', doc, renderTagLinkToHtml)}
++++\n
'''\n
@end{}
\n
[cols=">25%,^25%,50%"]\n
[frame="topbot"]\n
|===\n
^|Name | Type ^| Description\n
@foreach{property:properties}
	@code{propertyType=getDataType(property.type)}
	@code{arrayPrefix = property.array ? 'Array of ' : ''}
	@if{propertyType != null}
		\n
		|[[@{property.name}]]`@{property.name}`\n
		|`@{arrayPrefix}@{getDataType(property.type)}`\n
		|@if{property.doc != null}
		+++\n
		@{renderDocToHtml('', property.doc, renderTagLinkToHtml).trim()}
		+++\n
		@else{}-@end{}
	@end{}
@end{}
|===\n
